package com.hanserwei.mydemo.currying;

import java.util.ArrayList;
import java.util.List;

public class CarryingDemo02 {
    /*
     * 目标：把三份数据合在一起，逻辑既定，但数据不能一次得到。
     *
     * a->函数对象
     *    b->函数对象
     *          c->函数对象
     * */
    static Fb step1() {
        List<Integer> x = List.of(1, 2, 3);
        Fa fa = a -> b -> c -> {
            List<Integer> list = new ArrayList<>();
            list.addAll(a);
            list.addAll(b);
            list.addAll(c);
            return list;
        };
        return fa.op(x);
    }

    static Fc step2(Fb fb) {
        List<Integer> y = List.of(4, 5, 6);
        return fb.op(y);
    }

    static void step3(Fc fc) {
        List<Integer> c = List.of(7, 8, 9);
        fc.op(c).forEach(System.out::println);
    }

    public static void main(String[] args) {
        Fb fb = step1();
        Fc fc = step2(fb);
        step3(fc);
    }

    @FunctionalInterface
    interface Fa {
        Fb op(List<Integer> a);
    }

    @FunctionalInterface
    interface Fb {
        Fc op(List<Integer> b);
    }

    @FunctionalInterface
    interface Fc {
        List<Integer> op(List<Integer> c);
    }
}
